package com.firefly.service.repository.ums;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.firefly.dao.dao.ums.mapper.MenuMapper;
import com.firefly.dao.dao.ums.po.MenuPo;
import com.firefly.dao.dao.ums.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * @description: 权限菜单修改接口具体实现
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/11/29
 **/
@Repository
public class MenuRepository {
    private final MenuService menuService;
    private final MenuMapper menuMapper;
    @Autowired
    public MenuRepository(MenuService menuService, MenuMapper menuMapper){
        this.menuService = menuService;
        this.menuMapper = menuMapper;
    }
    public boolean createMenu(MenuPo entity){
        return menuService.save(entity);
    }
    public boolean updateByid(MenuPo entity){
		return menuService.updateById(entity);
    }
    public boolean sortById(MenuPo entity){
        UpdateWrapper<MenuPo> update = new UpdateWrapper<>();
        update.eq("id",entity.getId());
        update.set("sort",entity.getSort());
        return menuService.update(new MenuPo(),update);
    }
    public List<Integer> getIds(Integer id){
        /*// 查所有菜单出来
		List<MenuPo> list = menuService.list(null);
		// 置空所有ids的存放空间
		List<Integer> ids = TreeNodeUtils.getIds(id,list.stream().collect(Collectors.toList()));
        ids.add(id);
        return ids;*/
        return menuMapper.getAllChildId(id);
    }
    public boolean removeId(List<Integer> ids){
        return menuService.removeByIds(ids);
    }
}
